package com.iw.test.db;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.iw.adoms.entity.QrGoodsCode;
import com.iw.adoms.entity.neum.DepartType;
import com.iw.adoms.entity.neum.Status;
import com.iw.adoms.service.QrGoodsCodeService;
import com.iw.core.utils.HibernateUtils;

public class JSmsPointService extends DBBase {

	@Autowired
	private QrGoodsCodeService service;

	@Test
	public void testIntegrate() {
		String qrCode = "http://qr.alvinbaby.com?100001066659";
		String hql = "from QrGoodsCode where id in " + "(select g.qrCode.id from Goods g where g.department.id in (select dd.id from Department dd where dd.type.id in "
				+ "(select dt.id from DepartmentType dt where dt.name=?)) and g.state = ? and g.qrCode.id = " + "(select qq.id from QrGoodsCode qq where qq.qrCode = ? and qq.state != ?))";
		List<QrGoodsCode> qrList = service.findList(hql, DepartType.SD.v(), Status.HAS_OUT.getValue(), qrCode, Status.QR_HAD_INTEGRAL.getValue());
		System.out.println(qrList.size());

	}

	@Test
	public void testIntegrate2() {
		String iCode = "http://qr.alvinbaby.com?100001066659";

		String hql = "from QrGoodsCode where id in " + "(select g.qrCode.id from Goods g where g.department.id in (select dd.id from Department dd where dd.type.id in "
				+ "(select dt.id from DepartmentType dt where dt.name=?)) and g.state = ? and g.qrCode.id = " + "(select qq.id from QrGoodsCode qq where qq.qrCode = ? and qq.state != ?))";
		@SuppressWarnings("unchecked")
		List<QrGoodsCode> qrList = HibernateUtils.createQuery(service.getBaseDao().getNewSession(), hql, DepartType.SD.v(), Status.HAS_OUT.getValue(), iCode, Status.QR_HAD_INTEGRAL.getValue()).list();

		System.out.println(qrList.size());

	}

}
